﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using DataAccessLibrary;
using DataAccessLibrary.DAL;
using context;
using entities;

namespace BusinessLogicLibrary
{
    public class BookingModule
    {
        private readonly BookingDAO bookingDAO = new BookingDAO();

        public bool CreateBooking(int pCustomerID, List<int> pRoomID, DateTime pCheckInDate, DateTime pCheckOutDate)
        {
            pCheckInDate = pCheckInDate.Date;
            pCheckOutDate = pCheckOutDate.Date;
            if (pCheckInDate < pCheckOutDate)
            {
                throw new Exception("ERROR: CheckIn date must be earlier than CheckOut date");
            }

            pCheckInDate = pCheckInDate.Add(new TimeSpan(12, 0, 0, 0));
            pCheckOutDate = pCheckOutDate.Add(new TimeSpan(11, 0, 0, 0));
            var booking = new Booking
                              {
                                  CustomerID = pCustomerID,
                                  BookingDate = DateTime.Today
                              };

            var lstCheckIn = pRoomID.Select(rID => new CheckIn
                                                       {
                                                           RoomID = rID,
                                                           CheckInDate = pCheckInDate,
                                                           CheckOutDate = pCheckOutDate,
                                                           Available = false
                                                       }).ToList();

            return bookingDAO.InsertBooking(booking, lstCheckIn);
        }

        public bool DeleteBooking(int pBookingId)
        {
            return bookingDAO.DeleteBooking(pBookingId);
        }

        public List<Booking> GetBookingByCustomerId(int customerId)
        {
            return bookingDAO.SelectBookingByCustomerId(customerId);
        }


    }
}
